package com.toymate.ai.tts;

import cn.hutool.extra.spring.SpringUtil;
import com.toymate.ai.tts.model.aliyun.AliyunTtsService;
import com.toymate.ai.tts.model.azure.AzureTtsService;
import com.toymate.ai.tts.model.volcengine.VolcengineTtsService;
import com.toymate.common.constant.AiConstant;
import com.toymate.modules.iot.entity.IotRole;
import com.toymate.modules.iot.service.IotRoleService;

/**
 * STTFactory
 *
 * @author weirdor (179946422@qq.com)
 * @version v1.0.0
 */
public final class TTSFactory {


    private static IotRoleService iotRoleService;

    static {
        TTSFactory.iotRoleService = SpringUtil.getBean(IotRoleService.class);
    }

    public static AbstractTtsService build(IotRole role) {
        //根据角色ID查询角色信息
        TtsConfig config = iotRoleService.getValueObject(role.getRoleId(), "tts", TtsConfig.class);
        if (AiConstant.ttsService.ALIYUN.getValue().equals(config.getTtsType())) {
            return new AliyunTtsService(config);
        }
        if (AiConstant.ttsService.AZURE.getValue().equals(config.getTtsType())) {
            return new AzureTtsService(config);
        }
        if (AiConstant.ttsService.VOLCENGINE.getValue().equals(config.getTtsType())) {
            return new VolcengineTtsService(config);
        }
        return null;
    }
}
